package com.cspg.ssss.controller;

import com.alibaba.fastjson.JSONObject;
import com.cspg.ssss.domain.CheckBatchInst;
import com.cspg.ssss.domain.GsdgdwGradeViewEntity;
import com.cspg.ssss.service.*;
import com.cspg.ssss.util.DateUtil;
import com.cspg.ssss.vo.ResultVo;
import com.cspg.ssss.vo.ResultVoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/grade")
public class FlowController {
    @Autowired
    CheckBatchService checkBatchService;

    @Autowired
    ProblemService problemService;

    @Autowired
    WxSendMsgService wxSendMsgService;

    @Autowired
    DailyMessageService dailyMessageService;

    @Autowired
    ProblemGradeService problemGradeService;

    @GetMapping("/createBatch")
    public ResultVo createBatch(){
        CheckBatchInst inst = new CheckBatchInst();
        inst.setCheck_type(0);
        inst.setStart_date(DateUtil.getCurrentDate());
        checkBatchService.createCheckBatchInst(inst);
        inst.setCheck_type(1);
        checkBatchService.createCheckBatchInst(inst);
        ResultVo retvo = ResultVoUtil.success("success",null);
        return retvo;
    }

    @GetMapping("/syncProblem")
    public ResultVo syncProblem(){
        problemService.SycProblemFromDyffAndDfyy_ch();
        ResultVo retvo = ResultVoUtil.success("success",null);
        return retvo;
    }

    @GetMapping("/switchStage")
    public ResultVo switchStage(){
        problemGradeService.setNextStage(0);
        problemGradeService.setNextStage(1);
        ResultVo retvo = ResultVoUtil.success("success",null);
        return retvo;
    }

    @GetMapping("/sendmsg")
    public ResultVo sendmsg(@RequestParam String uid){

        List<String> ids = new ArrayList<String>();
        ids.add(uid);
        wxSendMsgService.sendTextMsgByList(ids,null,"测试","测试消息格式+++");
        wxSendMsgService.sendCheckTipInfo(ids,0);
        ResultVo retvo = ResultVoUtil.success("success",null);
        return retvo;

    }

    @GetMapping("/senddailymsg")
    public ResultVo senddailymsg(){

        dailyMessageService.sendDailyMessage(0);
        dailyMessageService.sendDailyMessage(1);
        dailyMessageService.sendRectifyMessage();
        ResultVo retvo = ResultVoUtil.success("success",null);
        return retvo;

    }

    @GetMapping("/testgetviewlist")
    public ResultVo getAllGsdgdwList(){
        List<GsdgdwGradeViewEntity> ls = problemGradeService.getAllGsdgdwGradeView();
        ResultVo retvo = ResultVoUtil.success("success",ls);
        return retvo;
    }
}
